package com.hexacta.hrs.sandbox.pr.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.hexacta.hrs.sandbox.pr.data.Dao;
import com.hexacta.hrs.sandbox.pr.model.Person;
import com.hexacta.hrs.sandbox.pr.model.Project;

public class ProjectServiceImpl implements ProjectService {
	
	@Autowired
	private Dao dao;

	public Dao getDao() {
		return dao;
	}

	public void setDao(Dao dao) {
		this.dao = dao;
	}
	
	public Long addProject(Project project) {
		return this.getDao().add(project);
	}

	@SuppressWarnings("unchecked")
	public List<Project> listAll() {
		return (List<Project>) this.getDao().listAll(Project.class);
	}

	public void removeProject(Project project) {
		this.getDao().remove(project);
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<Project> findProjectByName(String name) {
		return (List<Project>) this.getDao().findByName(Project.class, name);
	}

	@Override
	public Long addProject(Person leader, String name) {
		Project project = new Project();
		project.setLeader(leader);
		project.setName(name);
		return this.addProject(project);
	}
}